package view
{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.utils.ByteArray;

    import view.ImageLocator;

    public class Background extends Sprite
    {
        public var mountain:Bitmap = new ImageLocator.mountain();
        public var mountainData:BitmapData = mountain.bitmapData.clone();
        public var mountainX:int = 0;

        public var cloud:Bitmap = new ImageLocator.cloud();
        public var cloudData:BitmapData = cloud.bitmapData.clone();
        public var cloudX:int = 0;

        /*[Embed("movement.pbj", mimeType="application/octet-stream")]
        private var TestFilter:Class;
        private var shader:Shader = new Shader(new TestFilter() as ByteArray);
        private var filter:ShaderFilter;*/

        public function Background()
        {
            this.mountain.x = 0;
            this.mountain.y = 240;
            this.addChild(this.mountain);
            this.cloud.x = 0;
            this.cloud.y = 0;
            this.addChild(this.cloud);
        }

        public function display():void
        {
            this.graphics.clear();
            this.mountain.bitmapData.copyPixels(this.mountainData,
                                                new Rectangle(this.mountainX, 0, this.mountainData.width-this.mountainX, this.mountainData.height),
                                             new Point(0, 0));
            this.mountain.bitmapData.copyPixels(this.mountainData,
                                             new Rectangle(0, 0, this.mountainX, this.mountainData.height),
                                             new Point(this.mountainData.width-this.mountainX, 0));

            this.cloud.bitmapData.copyPixels(this.cloudData,
                                             new Rectangle(this.cloudX, 0, this.cloudData.width-this.cloudX, this.cloudData.height),
                                             new Point(0, 0));
            this.cloud.bitmapData.copyPixels(this.cloudData,
                                             new Rectangle(0, 0, this.cloudX, this.cloudData.height),
                                             new Point(this.cloudData.width-this.cloudX, 0));

        }

        public function move(speed:int):void
        {
            this.mountainX += speed / 4;
            this.mountainX %= this.mountainData.width;
            this.cloudX += speed;
            this.cloudX %= this.cloudData.width;
            //this.shader.data.speed = [speed];
            //this.filter = new ShaderFilter(this.shader);
            //this.cloud.filters = [this.filter];
        }
    }
}
